/*-----------------------------------------------------------------------------------*/
/*                                                                                   */
/* Copyright (c) 2008 Nuvoton Technology Corporation                                 */
/* All rights reserved                                                               */
/*                                                                                   */ 
/*-----------------------------------------------------------------------------------*/
/* File Contents:                                                                    */
/*   NUC900_PS2.h                                                                           */
/*                                                                                   */
/* This file contains:                                                               */
/*                                                                                   */
/* Project:                                                                          */
/*                                                                                   */
/*-----------------------------------------------------------------------------------*/

#ifndef _NUC900_PS2_H_
#define _NUC900_PS2_H_

#include "wbtypes.h"

/*-----------------------------------------*/
/* marco, type and constant definitions    */
/*-----------------------------------------*/
#define PS2_RX_BUFFSIZE             256

#define PS2_PORT0                   0
#define PS2_PORT1                   1

#define PS2_KEYBOARD                0
#define PS2_MOUSE                   1
#define PS2_BARCODE                 2

#define	PS2_ENABLE_TRAP_SHIFT		0
#define PS2_DISABLE_TRAP_SHIFT		1

#define PS2_ENABLE_RX_RELEASE		0
#define PS2_DISABLE_RX_RELEASE		1

#define PS2_BLOCK				    0
#define PS2_NON_BLOCK			    1

// Register Base address
#define PS20_BA						PS2_BA
#define PS21_BA						(PS2_BA + 0x100)

// Register offset
#define PS2_CMD						0x0
#define PS2_STS						0x4
#define PS2_SCANCODE				0x8
#define PS2_ASCII					0xc
					


/*
	Define PS2 error code.
*/
#define PS2_ERR_ID		            0xFFFF1500	        /* PS2 library error ID             */
#define PS2_ENOTTY	                (1 | PS2_ERR_ID)    /* Command not support              */
#define PS2_ENODEV                  (2 | PS2_ERR_ID)    /* Interface number is incorrectly  */
#define PS2_EIO                     (3 | PS2_ERR_ID)    /* Read/Write error                 */

#define PS2_RXBUFFULL               (4 | PS2_ERR_ID)    /* RX buffer is full                */
#define PS2_SENDCOMMTIMEOUT         (5 | PS2_ERR_ID)    /* Send host command timeout        */
#define PS2_RECACKTIMEOUT           (6 | PS2_ERR_ID)    /* Receive device ACK timeout       */
#define PS2_RECACKERROR             (7 | PS2_ERR_ID)    /* The received device ACK is wrong */

/*
	Define bits of PS2 host controller status register.
*/
#define PS2_STS_RX_IRQ		        0x01
#define PS2_STS_RX_2BYTES           0x03  /* the receive 2 byte flag is set with receive interrupt bit */
#define PS2_STS_TX_IRQ              0x10
#define PS2_STS_TX_ERR              0x20

/*
	Define ioctl commands.
*/
#define PS2_IOC_SET_RX_MODE             1
#define PS2_IOC_FLUSH_RX_BUFFER         2
#define PS2_IOC_SET_CALLBACK_FUN        3
#define PS2_IOC_DISABLE_CALLBACK_FUN	4
#define PS2_IOC_SET_TRAP_SHIFT			5
#define PS2_IOC_SET_RX_RELEASE			6
#define PS2_IOC_GET_ERR_STATUS          7

/* 
    Define some keyboard commands. Not support all of keyboard commands. 
    Not supported commands: F0 F3 F6 F7 F8 F9 FA FB FC FD FE             
*/
#define KBCMD_SETLED        0xED  /* bit0: Scroll Lock. bit1: Num Lock. bit2: Caps Lock. */
#define KBCMD_ECHO          0xEE
#define KBCMD_ID			0xF2
#define KBCMD_ENABLE        0xF4
#define KBCMD_DISABLE       0xF5
#define KBCMD_RESET         0xFF

/* 
	Define keyboard status. 
*/
#define KBSTS_ACK			0xFA
#define KBSTS_RESET_OK		0xAA
#define KBSTS_ERR_COMD		0xFE

/*
	Define some mouse commands.
*/
#define MOUSECMD_SET_SCALE				0xE6
#define MOUSECMD_SET_RESOLUTION			0xE8
#define MOUSECMD_SET_SAMPLE_RATE		0xF3
#define MOUSECMD_ENABLE_DATA_REPORT		0xF4
#define MOUSECMD_RESET					0xFF

/* 
	Define mouse status. 
*/
#define MOUSESTS_ACK		        	0xFA
#define MOUSESTS_BATCOMPLT				0xAA  /* Basic Assurance Test (BAT) successful */
#define MOUSESTS_DEVICE_ID				0x00

/* 
	Define some specially keys on PS2 keyboard. The max scan code is 0x83. 
*/
#define KB_E1_PAUSE			0x90

/* 
	Define PS2 RX data struct.
*/
typedef struct{
	UINT8 ucExtendByte;
	UINT8 ucScanCode;
	UINT8 ucAsciiCode;
}PS2_DATA_T;

/*-----------------------------------------*/
/* global interface variables declarations */
/*-----------------------------------------*/


/*-----------------------------------------*/
/* interface function declarations         */
/*-----------------------------------------*/
INT ps2Init (VOID);
INT ps2Open (INT param, INT devid);
INT ps2Read(INT nNum, PUINT8 pucBuf, UINT32 uLen);
INT ps2Ioctl(INT nNum, UINT32 uCmd, UINT32 uArg0, UINT32 uArg1);
INT ps2Write(INT nNum, PUINT8 pucBuf, UINT32 uLen);   
INT ps2Release (INT fd);



#endif
